package com.bcu.calculus.controller;

import com.bcu.calculus.entity.Message;

import com.bcu.calculus.entity.Total;

import com.bcu.calculus.entity.User;
import com.bcu.calculus.service.TotalService;

import com.bcu.calculus.service.UserInfoService;
import com.bcu.calculus.utils.SendUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;

@Api(tags = "08  总分处理模块")
@RestController
@RequestMapping("/api/total")
public class TotalController {

    @Resource
    private TotalService totalService;
    @Resource
    private UserInfoService userInfoService;

    @ApiOperation(value = "添加总分")
    @PostMapping(value = "/add")
    public Message<?> addTotal(Total total){
        String totalId = "TO" + SendUtil.genSendId();
        total.setTotalScoreId(totalId);
        return totalService.addTotal(total);
    }

    @ApiOperation(value = "删除总分")
    @DeleteMapping(value = "/del")
    public Message<?> delTotal(String totalScoreId){
        return totalService.delTotal(totalScoreId);
    }

    @ApiOperation(value = "修改总分")
    @PutMapping(value = "/update")
    public Message<?> updateTotal(Total total){
        return totalService.updateTotal(total);
    }

    @ApiOperation(value = "查找所有总分")
    @GetMapping(value = "/getAll")
    public Message<List<Total>> findAll(){
        return totalService.selectAll();
    }


    @ApiOperation(value = "根据userId查总分")
    @GetMapping(value = "/getByUserId")
    public Message<Total> findOneByUserId(String userId,Integer semId){
        return totalService.selectOneByUserId(userId,semId);
    }


    @ApiOperation(value = "根据主键查总分")
    @GetMapping(value = "/getByPK")
    public Message<Total> findOneByPK(String totalScoreId){
        return totalService.selectOneByPrimaryKey(totalScoreId);
    }


    @ApiOperation(value = "(按党小组)获取当前学期各分数段人数")
    @GetMapping(value = "/totalcount")
    public Message<List> totalcount(Integer semId){
        return totalService.totalcount(semId);
    }

    @ApiOperation(value = "各党小组平均分、及格率，最高分及姓名")
    @GetMapping(value = "/totalBranch")
    public Message<List> totalBranch(Integer totalSemId){
        return totalService.totalBranch(totalSemId);
    }

    @ApiOperation(value = "发布成绩")
    @PostMapping(value = "/pushScore")
    public Message<?> PushScore(Total total){
        return totalService.pushOneScore(total);
    }


    @ApiOperation(value = "根据sem_id获取分数统计数据")
    @GetMapping(value = "/totalCount")
    public Message<?> totalCount(Integer totalSemId){
        return totalService.totalCount(totalSemId);
    }

    @ApiOperation(value = "获取当前学期所有用户总分")
    @GetMapping(value = "/getallUserScoreBySemId")
    public Message<?> getAllUserScoreThisSemId(Integer semId) {
        return userInfoService.getAllUserScoreThisSemId(semId);
    }

    @ApiOperation(value = "获取当前学期一个用户总分")
    @GetMapping(value = "/getOneUserScoreBySemId")
    public Message<?> getOneUserScoreThisSemId(Integer semId,String userId) {
        return userInfoService.getOneUserScoreThisSemId(semId,userId);
    }


    @ApiOperation(value = "获取各各分数段人数")
    @GetMapping(value = "/count")
    public Message<List> count(Integer totalSemId){
        return totalService.count(totalSemId);
    }


    @ApiOperation(value = "获取所有人的排名")
    @GetMapping(value = "/getallrank")
    public  Message<List> getAllRank(Integer totalSemId){
        return totalService.getAllRank(totalSemId);
    }

    @ApiOperation(value = "获取党小组排名")
    @GetMapping(value = "/getAllBranchRank")
    public  Message<List> getAllBranchRank(Integer userBranch, Integer totalSemId){
        return totalService.getAllBranchRank(userBranch,totalSemId);
    }

    @ApiOperation(value = "获取某个具体用户在当下组内的排名")
    @GetMapping(value = "/getOneRankInBranch")
    public Message<Integer> getOneRankingInBranch(String userId,Integer branch,Integer totalSemId){
        return totalService.getOneUserRankInBranch(userId,branch,totalSemId);
    }

    @ApiOperation(value = "获取某个具体用户的排名")
    @GetMapping(value = "/getOneRank")
    public Message<Integer> getOneRank(String userId,Integer totalSemId){
        return totalService.getOneUserRank(userId,totalSemId);
    }

    @ApiOperation(value = "查看当前学期个人分数")
    @GetMapping(value = "/getTotalScore")
    public Message<Integer> getTotalScore(String totalUserId, Integer totalSemId){
        return totalService.getTotalScore(totalUserId,totalSemId);
    }

}
